package myStack;

import java.util.Stack;

public class text {
    public static void main(String[] args) {
        MyQueue myQueue = new MyQueue();
        myQueue.push(1); // queue is: [1]
        myQueue.push(2); // queue is: [1, 2] (leftmost is front of the queue)
        System.out.println(myQueue.peek()); // return 1
        System.out.println(myQueue.pop()); // return 1, queue is [2]
        System.out.println(myQueue.empty()); // return false
    }
    public static void main2(String[] args) {
        MinStack minStack = new MinStack();
        minStack.push(-1);
        minStack.push(0);
        minStack.push(-3);

    }
    public static void main1(String[] args) {
        MyStack myStack = new MyStack(3);
        myStack.push(1);
        myStack.push(2);
        myStack.push(3);
        myStack.push(4);

        System.out.println(myStack.pop());//4
        System.out.println(myStack.pop());//4
        System.out.println(myStack.pop());//4
        System.out.println(myStack.peek());
    }
    public boolean IsPopOrder (int[] pushV, int[] popV) {
        // write code here
        Stack<Integer> stack = new Stack<>();
        int j = 0;
        for(int i = 0;i < pushV.length;i++) {
                stack.push(pushV[i]);
                while(!stack.empty() && j < popV.length && stack.peek() == popV[j]) {
                    stack.pop();
                    j++;
                }
        }

        return stack.empty();
    }

    public int evalRPN(String[] tokens) {
        Stack<Integer> stack = new Stack<> ();
        for(int i = 0;i < tokens.length;i++) {
            String s = tokens[i];
            if(isNumber(s)) {
                stack.push(Integer.getInteger(s));
            }else {
                int n2 = stack.pop();
                int n1 = stack.pop();
                switch(s) {
                    case "+":
                        stack.push(n1 +n2);
                        break;
                    case "-":
                        stack.push(n1 - n2);
                        break;
                    case "*":
                        stack.push(n1 * n2);
                        break;
                    case "/":
                        stack.push(n1 / n2);
                        break;
                }
            }
        }
        return stack.pop();
    }
    private boolean isNumber(String s) {
        if(s.equals("+") || s.equals("-")|| s.equals("*") || s.equals("/")) {
            return false;
        }
        return true;
    }

    public boolean isValid(String s) {
        Stack<Character> stack = new Stack<>();
        for(int i = 0 ; i < s.length();i++) {
            char ch = s.charAt(i);
            if(ch == '(' || ch == '[' || ch == '{') {
                stack.push(ch);
            }else {
                if(stack.empty()) {
                    return false;
                }
                char ch2 = stack.peek();
                if(ch == '}' && ch2 == '{' || ch == ')' && ch2 == '(' || ch == ']' && ch2 == '[') {
                    stack.pop();
                }else {
                    return false;
                }
            }
        }
        if(stack.empty()) {
           return false;
        }
        return true;
    }
}
